using System.Collections;
using UnityEngine;

public class Mouth : MonoBehaviour
{
	[Header("Requirement")]
	public Creature creature;

	private bool @break;

	private void OnTriggerEnter2D(Collider2D collision)
	{
		TryToEat(collision.GetComponent<IFood>());
	}

	private void TryToEat(IFood food)
	{
		if (food.IsEatable(creature) && !@break)
		{
			creature.Eat(food.Eat(), food.GetSize());
			creature.OverwriteAnimation(creature.headAnimation);
			creature.OverwriteAnimation(creature.mouthAnimation);
			if (creature.IsEnemy() && food is Carrion)
			{
				@break = true;
				StartCoroutine(EndBreak());
			}
		}
	}

	private IEnumerator EndBreak()
	{
		yield return new WaitForSeconds(1f);
		@break = false;
	}
}
